<!doctype html>
<html>
	<head>
		<!--设置页面编码为utf-8-->
		<meta charset="utf-8">
		<!-- 当前页面三要素 -->
		<meta name="Keywords" content="">
		<meta name="Description" content="">
		<title>工厂模式</title>

	</head>
	<body>
		
		<script type="text/javascript">

			//factory model
			function createPerson(name, age, job){
				var obj = Object();
				obj.name = name;
				obj.age = age;
				obj.job = job;
				obj.sayName = function(){
					document.write('My name is ' + obj.name + '<br />')
				};
				return obj;
			}

			var zhangsan = createPerson('zhangsan', 20, 'doctor');
			zhangsan.sayName();

			//constructor model
			function Person(name, age, job){
				this.name = name;
				this.age = age;
				this.job = job;
				this.sayName = function(){
					document.write('My name is ' + this.name + '<br />')
				};
			}
			var lisi = new Person('lisi', 28, 'driver');
			lisi.sayName();
		</script>
	</body>
</html>
